package com.example.warehouse.sys.controller;

import com.example.warehouse.common.web.JsonResult;
import com.example.warehouse.sys.pojo.param.SysUserRoleAddNewParam;
import com.example.warehouse.sys.service.IUserRoleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/sys/userRole")
@Api(tags = "2.5. 用户角色管理")
@Validated
public class UserRoleController {
    @Autowired
    private IUserRoleService userRoleService;

    @ApiOperation("给用户分配角色")
    @ApiOperationSupport(order = 100)
    @PostMapping("insert/addUserRole")
    @PreAuthorize("hasAuthority('/sys/userRole/insert/addUserRole')")
    public JsonResult insert(@Validated SysUserRoleAddNewParam sysUserRoleAddNewParam) {
        log.debug("开始处理 [给用户分配角色] 的请求, 参数: {} ", sysUserRoleAddNewParam);
        userRoleService.addRoleToUser(sysUserRoleAddNewParam);
        return JsonResult.ok();

    }
}
